#include <stdio.h>

#if 0
    //字节对齐：按照最大的数据类型进行对齐
    //对齐内部的多个变量依旧遵循对齐规则
    //小的数据类型放一起
    //数组的大小定义放2的指数级
    struct Test
    {
        int a;
        char b;
    };
    typedef struct Test test;

    int main()
    {
        test t;
        printf("%ld\n", sizeof(test));
        printf("%p %p %p\n", &t, &t.a, &t.b);

        return 0;
    }
#endif

#if 0
    struct Test
    {
        int a;
        char b;
        char c；
    };
    typedef struct Test test;

    int main()
    {
        test t;
        printf("%ld\n", sizeof(test));
        printf("%p %p %p\n", &t, &t.a, &t.b, &t.c);

        return 0;
    }
#endif

#if 0
    struct Test
    {
        int a;
        char b;
        int c;
    };
    typedef struct Test test;

    int main()
    {
        test t;
        printf("%ld\n", sizeof(test));
        printf("%p %p %p %p\n", &t, &t.a, &t.b, &t.c);

        return 0;
    }
#endif

#if 0
    struct Test
    {
        char c;
        char b;
        int a;
        double d;
    };
    typedef struct Test test;

    int main()
    {
        test t;
        printf("%ld\n", sizeof(test));
        printf("%p %p %p %p %p\n", &t, &t.c, &t.b, &t.a, &t.d);

        return 0;
    }
#endif

#if 0
    struct Test
    {
        char c;
        char b;
        int *a;
        double d;
    };
    typedef struct Test test;

    int main()
    {
        test t;
        printf("%ld\n", sizeof(test));
        printf("%p %p %p %p\n", &t, &t.c, &t.b, &t.a, &t.d);

        return 0;
    }
#endif

#if 0
    struct Test
    {
        char c[9];  //数组属于数据结构，不是数据类型，所以还是按8个字节对齐
        int *a;
        double d;
    };
    typedef struct Test test;

    int main()
    {
        test t;
        printf("%ld\n", sizeof(test));
        printf("%p %p %p %p\n", &t, &t.c, &t.a, &t.d);

        return 0;
    }
#endif

#if 1
    struct Test
    {
        char c[9];  //数组属于数据结构，不是数据类型，所以还是按8个字节对齐
        int a;
        double d;
    };
    typedef struct Test test;

    int main()
    {
        test t;
        printf("%ld\n", sizeof(test));
        printf("%p %p %p %p\n", &t, &t.c, &t.a, &t.d);

        return 0;
    }
#endif